package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-06-05 23:04
 */
public class LeetCode2460_ApplyOperations {
    public int[] applyOperations(int[] nums) {
        for (int i = 0, j = 1; j < nums.length; i++, j++) {
            if (nums[i] == nums[j]) {
                nums[i] = 2 * nums[i];
                nums[j] = 0;
            }
        }
        int fast = 0, slow = 0;
        while (fast < nums.length) {
            if (nums[fast] != 0) {
                int temp = nums[fast];
                nums[fast] = nums[slow];
                nums[slow] = temp;
                slow++;
            }
            fast++;
        }
        return nums;
    }
    
}
